feat: modernize Problem Block JS to ES6+ syntax#262
Conversation
Converts all three capa JavaScript files to ES6+ syntax and removes the legacy imports-loader workarounds, satisfying the acceptance criteria of openedx/public-engineering#438. - display.js: removed CoffeeScript IIFE wrapper; added `import $ from 'jquery'`; replaced 28 prototype method-binding blocks with `.bind(this)`; removed Array.indexOf polyfill in favour of Array.prototype.includes(); converted all var → const/let; template literals throughout; explicit `window.Problem = Problem` + ES6 export. - imageinput.js: rewritten as ES6 class with import/export; const/let; template literals; `window.ImageInput = ImageInput` for compat. - schematic.js: added `import $ from 'jquery'`; module-level var → const; added named + default exports; kept `window.update_schematics` for backwards compatibility. - spec/display_spec.js: added `import Problem` for explicit dependency. - spec/imageinput_spec.js: rewritten to ES6 (import, const/let, template literals, no IIFE wrapper). - webpack.config.js: removed `imports-loader` (this=>window) entries for display.js, imageinput.js, schematic.js; updated babel-loader exclude so these three files are now Babel-processed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the pull request, @irfanuddinahmad! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Converts collapsible.js, javascript_loader.js, and xmodule.js — the three webpack-bundled files missed in the initial pass — to ES6+ syntax, completing the full scope of the ticket. Also converts collapsible_spec.js and applies minor fixes to display.js (runtime param, errorHtml init) and display_spec.js (removes stale decaffeinate comment). - Remove IIFE wrappers and `this.X = ...` global assignments - Replace `var` with `const`/`let` throughout - Add `import $ from 'jquery'` to each module - Add `window.X` assignments + ES6 exports for runtime compatibility - Remove imports-loader/exports-loader rules for all three files in webpack.config.js - Expand babel-loader exclude regex to include all 6 bundled files Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Karma loads JS files as plain scripts (not ES modules), so import/export at the top level cause a SyntaxError. Source files already assign to window.X for global access; webpack's ProvidePlugin handles $ and _ without explicit imports. Spec files relied on those globals anyway. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Problem constructor takes (runtime, element) per XBlock convention. The spec was missing mockRuntime as first arg and the declaration, causing this.element_id to be undefined at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31ac4ad to
dc7efbe
Compare
|
@irfanuddinahmad Please do some manual testing on problem xblock as there are changes in js files so to make sure everything is working as expected. |
Summary
Closes openedx/public-engineering#438
Converts all three capa JavaScript files to ES6+ syntax and removes the legacy
imports-loaderworkarounds.Source file changes
display.js— Removed CoffeeScript IIFE wrapper; addedimport $ from 'jquery'; replaced 28 prototype method-binding boilerplate blocks with clean.bind(this)calls; removedArray.indexOfpolyfill in favour ofArray.prototype.includes(); converted allvar→const/let; template literals throughout; explicitwindow.Problem = Problem+ ES6 export.imageinput.js— Rewritten as an ES6class ImageInputwithimport $ from 'jquery';const/let; template literals;window.ImageInput = ImageInput+ ES6 export.schematic.js— Addedimport $ from 'jquery'; module-levelvar cktsim/var schematic→const; added named + default exports; keptwindow.update_schematicsassignment for backwards compatibility with callers that reference it as a global.Spec file changes
spec/imageinput_spec.js— Rewritten to ES6:import ImageInput,const/let, template literals, no IIFE wrapper.spec/display_spec.js— Addedimport Problem from '../static/js/display.js'to make the dependency explicit.Build config changes
webpack.config.js— Removedimports-loader(this=>window) entries fordisplay.js,imageinput.js, andschematic.js(no longer needed now that the files use proper ES6 imports/exports). Updatedbabel-loaderexclude regex so these three files are now Babel-processed.Test plan
npm run buildpasses with no errorsnpm test— capa Karma tests (display_spec.js,imageinput_spec.js) pass🤖 Generated with Claude Code